import Vue from 'vue'
import Vuex from 'vuex'
import hostmodeule from './modeules/hostmodeule'

import { session, local } from '@/common/utils'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userinfo: null,
    audioId: '',
    audioIndex: '',
    audioDate: 0,
    currentTime: '0:00',
    totalTime: '2:59',
    audioplayMode: 0,
    isSongsNull: true,
  },
  mutations: {
    getAudioobj(state, obj) {
      state.audioId = obj
      // 获取歌单
      const songs = session.get('songs')
      // 查找歌曲下标
      const itemIndex = songs.findIndex(item => item.id === obj.id)
      state.audioIndex = itemIndex
    },
    getAudioDate(state, date) {
      state.currentTime = date.curren
      state.audioDate = date.left
    },
    getTotaTime(state, total) {
      state.totalTime = total
    },
    getPlayMode(state, num) {
      state.audioplayMode = num
    },
    getisSongsNull(state, data) {
      state.isSongsNull = data
    },
    getuserToken(state, obj) {
      if (obj instanceof Object) {
        local.set('userinfo_Token', obj)
        state.userinfo = obj.userinfo
        return
      }
      state.userinfo = null
    },
  },
  actions: {},
  modules: {
    hostmodeule,
  },
})
